package com.hdc.hdc.warehouseManage.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * 统一异常处理类 异常处理器。该类会处理所有在执行标有@RequestMapping注解的方法时发生的异常
 * 
 * @author gjy
 *
 *         2018年3月16日下午4:03:16
 */
@Controller 
public class MyExceptionResolve implements HandlerInterceptor{

	private static final Logger log = LoggerFactory.getLogger(MyExceptionResolve.class);

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		
		if (response.getStatus()==500) {
			
			log.info("出现异常，进入500页面");
			
			modelAndView.setViewName("exception/ex");
			
		}
		
		
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		// TODO Auto-generated method stub
		
	}


}
